"""爬取萍乡学院官网，并保存到文件"""

import requests


def get_html_text(url):
    try:
       r = requests.get(url)
       r.raise_for_status()
       r.encoding = r.apparent_encoding
       return r.text
    except requests.RequestException as e:
        print("请求失败：", e)
        return ""


def save_text(text, target_path):
    with open(target_path, "w", encoding="utf-8") as file:
        file.write(text)


if __name__ == '__main__':
    html_file_path = r'萍乡学院.html'
    url = 'https://www.pxc.jx.cn/'
    text = get_html_text(url)
    save_text(text, html_file_path)
  
